const app = getApp()

let pageNo = 1;

Page({
  data: {
    imgUrls: [{
        selected: true,
        photo: 'http://39.104.123.0/image/time1.jpeg',
        stype: true
      },
      {
        selected: false,
        photo: 'http://39.104.123.0/image/time3.jpeg',
        stype: true
      },
      {
        selected: false,
        photo: 'http://39.104.123.0/image/time4.jpeg',
        stype: true
      },
      {
        selected: false,
        photo: 'http://39.104.123.0/image/time2.jpeg',
        stype: true
      },

    ],

    orderList: [],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,




    pageLoad: false,
    orderStatus: {
      WAIT_PAY: '未送货',
      WAIT_TAKE: '送货中',
      FINISHED: '已完成',
      CANCELED: '已取消'
    },
  },

  calling: function(e) {
    var phone = e.currentTarget.id;
    console.log(e)
    wx.makePhoneCall({
      phoneNumber: phone, //此号码并非真实电话号码，仅用于测试
      success: function() {
        console.log("拨打电话成功！")
      },
      fail: function() {
        console.log("拨打电话失败！")
      }
    })
  },
  onLoad: function(e) {
    var that = this
    console.log(e)
    that.init();

  },
  init: function() {
    var that = this
    wx.request({
      url: app.data.baseUrl + '/transaction/DeliveryNoteMgrAction!list',
      method: 'post',
      data: {
        'deliveryNote.dn_status ': 20
      },
      header: app.globalData.header,
      success: function(res) {
        var rows = res.data.rows;
        console.log('init')
        console.log(res);
        that.gatCart(rows[0].id)
        // for(let i=0;i<rows.length;i++){
        //   console.log("for")
        //   that.gatCart(rows[].id)
        // }

      },
      fail: function(e) {
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      },
    })
  },
  gatCart: function(id) {
    var that = this
    console.log(id)
    wx.request({
      url: app.data.baseUrl + '/transaction/DeliveryNoteMgrAction!listOrderForm',
      method: 'get',
      data: {
        'deliveryNote.id': id
      },
      header: app.globalData.header,
      success: function(res) {
        var rows = res.data.rows;
        console.log('gatCart');
        console.log(res)
        var orderist = that.data.orderList
        orderist.push(rows)
        that.setData({
          orderList: rows,

          // orderList: orderist,  等待修改
        });
      },
      fail: function(e) {
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      },
    })
  },

  toDetail: function(e) {
    var that = this;
    var id = e.currentTarget.id
    console.log('toDetail')
    console.log(e)
    var orderlist = that.data.orderList
    for (let i = 0; i < orderlist.length; i++) {
      if (orderlist[i].id == id) {
        let str = JSON.stringify(orderlist[i]);
        console.log(str)
        wx.navigateTo({
          url: '/pages/order/detail/index?order=' + str,
        })
      }
    }
  },

  backOrder: function(e) {
    var that = this;
    wx.showToast({
      title: '已退单',
    })
  },
  postOrder: function(e) {
    var that = this;

    wx.showToast({
      title: '已确认接单',
    })
  },
  printOrder: function(e) {
    wx.showToast({
      title: '功能开发中',
    })
  }



})